package com.oa.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;

/**
 * @Description 字符过滤器
 * @Author hyl
 * @Date 2022/7/7 8:56
 **/
@WebFilter(filterName = "EncodeFilter",urlPatterns = "/*",
		initParams = {@WebInitParam(name = "encode",value = "utf-8")})
public class EncodeFilter implements Filter {
	private String encode = null;

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println(this.getClass().getName()+"init");
		 String tmp = filterConfig.getInitParameter("encode");
		 if(encode == null){
		 	encode = tmp;
		 }
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		//处理字符编码
		request.setCharacterEncoding("utf-8");
		//决定用户请求是否进入到==》servlet
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {

	}
}
